package com.example.taobao;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.List;

public class GoodsAdapter extends ArrayAdapter<Goods> {
    private int resourceId;
    public GoodsAdapter(Context context, int textid, List<Goods> objects){
        super(context,textid,objects);
        resourceId = textid;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Goods goods = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        ImageView goodsImage = (ImageView) view.findViewById(R.id.goods_image);
        TextView goodsName = (TextView) view.findViewById(R.id.goods_name);
        TextView goodsMessage = (TextView) view.findViewById(R.id.goods_message);
        TextView goodsValue = (TextView) view.findViewById(R.id.goods_value);
        TextView goodsValue2 = (TextView) view.findViewById(R.id.goods_value2);
        TextView goodsBought = (TextView) view.findViewById(R.id.goods_bought);
        TextView goodsAddress = (TextView) view.findViewById(R.id.goods_address);
        goodsImage.setImageResource(goods.getImageId());
        goodsName.setText(goods.getName());
        goodsMessage.setText(goods.getMessage());
        goodsValue.setText(goods.getValue());
        goodsValue2.setText(goods.getValue());
        goodsBought.setText(goods.getBought());
        goodsAddress.setText(goods.getAddress());
        return view;
    }
}
